home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 1996 March / Amiga-CD 1996 #3.iso / pd-software / mui_3.1 / developer / c / examples / wbman.c < prev   
C/C++ Source or Header  |  1996-01-19  |  36KB  |  1,562 lines

  1.  
  2.   /**********************************************\
  3.   *                                              *
  4.   *  WbMan                                       *
  5.   *                                              *
  6.   *  Version: 0.42 (27.8.93)                     *
  7.   *                                              *
  8.   *  Copyright 1993 by kMel, Klaus Melchior      *
  9.   *  kmel@eifel.adsp.sub.org, 2:242/7.2@Fidonet  *
  10.   *                                              *
  11.   *  Manages the tools in the WBStartup-         *
  12.   *  Folder, the ToolTypes could be changed.     *
  13.   *                                              *
  14.   \**********************************************/
  15.  
  16. /* DMAKE */
  17.  
  18. /* TAB=4 */
  19.  
  20.  
  21.  
  22.  
  23. /*** escape sequences ***/
  24.  
  25. #define eR "\033r"
  26. #define eC "\033c"
  27. #define eL "\033l"
  28.  
  29. #define eN "\033n"
  30. #define eB "\033b"
  31. #define eI "\033i"
  32.  
  33. #define ePB "\0332"
  34. #define ePW "\0338"
  35.  
  36.  
  37.  
  38.  
  39. /*** includes ***/
  40.  
  41. #include "demo.h"
  42. #define MAXNAMELEN 256
  43.  
  44. #include <exec/memory.h>
  45. #include <workbench/workbench.h>
  46. #include <clib/icon_protos.h>
  47.  
  48.  
  49.  
  50.  
  51. /*** ids ***/
  52.  
  53. enum ids {
  54.     ID_DUMMY,
  55.     ID_ABOUT,
  56.     ID_RESCAN, ID_SELECT_ALL, ID_SELECT_NONE, ID_SELECT_PATTERN,
  57.     ID_EDIT, ID_LV_ACTIVE,
  58.     ID_ACTIVATE, ID_TOGGLE, ID_DEACTIVATE, ID_RESTORE,
  59.     ID_PERFORM, ID_QUIT,
  60.  
  61.     ID_STRING_OK, ID_STRING_CANCEL,
  62.  
  63.     ID_EDIT_LV_ACTIVE,
  64.     ID_EDIT_NEW, ID_EDIT_COPY, ID_EDIT_REMOVE,
  65.     ID_EDIT_ACTIVATE, ID_EDIT_DEACTIVATE,
  66.     ID_EDIT_ST_READY,
  67.     ID_EDIT_SAVE, ID_EDIT_CANCEL,
  68. };
  69.  
  70. enum mode_change {
  71.     MODE_ACTIVATE, MODE_DEACTIVATE,
  72.     MODE_TOGGLE, MODE_RESTORE,
  73. };
  74.  
  75.  
  76.  
  77.  
  78. /*** variables ***/
  79.  
  80. static APTR app;
  81. static APTR wi_main;
  82. static APTR lv_tools;
  83. static APTR bt_activate, bt_toggle, bt_deactivate;
  84. static APTR bt_edit;
  85. static APTR tx_info;
  86. static APTR bt_perform, bt_quit;
  87.  
  88. static APTR wi_string_request;
  89. static APTR st_string;
  90. static APTR bt_string_ok, bt_string_cancel;
  91.  
  92. static APTR wi_edit;
  93. static APTR tx_edit;
  94. static APTR lv_edit;
  95. static APTR bt_edit_new, bt_edit_copy, bt_edit_remove;
  96. static APTR bt_edit_activate, bt_edit_deactivate;
  97. static APTR st_edit_string, st_edit_default;
  98. static APTR bt_edit_save, bt_edit_cancel;
  99.  
  100.  
  101. static struct DiskObject *disk_object;
  102. static BOOL temp_dobj_flag;
  103.  
  104. static BOOL edit_window_open = FALSE;
  105. static BOOL string_request_open = FALSE;
  106.  
  107.  
  108.  
  109.  
  110. /*** funcs ***/
  111.  
  112. /*** clear tools_listview ***/
  113.  
  114. BOOL clear_tools_list(void)
  115. {
  116.     DoMethod(lv_tools, MUIM_List_Clear);
  117.  
  118.     return(TRUE);
  119. }
  120.  
  121.  
  122.  
  123.  
  124. /*** insert tools in tools_listview ***/
  125.  
  126. BOOL insert_tools_list(void)
  127. {
  128.     BOOL ok = FALSE;
  129.     struct FileInfoBlock *fib;
  130.  
  131.     /*** alloc mem for fileinfoblock ***/
  132.     if (fib = AllocDosObject(DOS_FIB, NULL))
  133.     {
  134.         BPTR lock;
  135.  
  136.         /*** lock on the wbstartup-directory ***/
  137.         if (lock = Lock("SYS:WBStartup/", ACCESS_READ))
  138.         {
  139.             /*** first examine ***/
  140.             Examine(lock, fib);
  141.  
  142.             /*** scan, until last entry ***/
  143.             while (ExNext(lock, fib) && (IoErr()!=ERROR_NO_MORE_ENTRIES))
  144.             {
  145.                 /*** mui refresh ***/
  146.                 DoMethod(app, MUIM_Application_InputBuffered);
  147.  
  148.                 /*** insert fib-entry ***/
  149.                 DoMethod(lv_tools, MUIM_List_Insert, &fib, 1, MUIV_List_Insert_Sorted);
  150.             }
  151.  
  152.             UnLock(lock);
  153.             ok = TRUE;
  154.         }
  155.  
  156.         FreeDosObject(DOS_FIB, fib);
  157.     }
  158.  
  159.     return(ok);
  160. }
  161.  
  162.  
  163.  
  164.  
  165. /*** rescan filenames of tools in the wbstartup-path ***/
  166.  
  167. void rescan_tools_list(void)
  168. {
  169.     if (!(
  170.         clear_tools_list() &&
  171.         insert_tools_list()
  172.         ))
  173.     {
  174.         fail(app,"Lock on 'SYS:WBStartup/' failed !");
  175.     }
  176. }
  177.  
  178.  
  179.  
  180.  
  181. /*** check tool, if it exists in wbstartup-path ***/
  182.  
  183. BOOL check_tool_name(char *n)
  184. {
  185.     char *fn;
  186.     BPTR fh;
  187.  
  188.     /*** alloc mem for complete filename ***/
  189.     if (fn = AllocMem(MAXNAMELEN, MEMF_ANY))
  190.     {
  191.         sprintf(fn, "SYS:WBStartup/%s", n);
  192.  
  193.         if (fh = Open(fn, MODE_OLDFILE))
  194.             Close(fh);
  195.  
  196.         FreeMem(fn, MAXNAMELEN);
  197.     }
  198.  
  199.     return((BOOL) fh);
  200. }
  201.  
  202.  
  203.  
  204.  
  205. /*** count active & inactive tools ***/
  206.  
  207. void count_tools_list(void)
  208. {
  209.     ULONG i;
  210.     UWORD nr_active = 0, nr_inactive = 0, nr_changed = 0;
  211.     char *line;
  212.  
  213.     /*** count ***/
  214.     for (i=0; ; i++)
  215.     {
  216.         DoMethod(lv_tools, MUIM_List_GetEntry, i, &line);
  217.  
  218.         /*** last line ? ***/
  219.         if (!line)
  220.             break;
  221.  
  222.         /*** count tools ***/
  223.         if (*(line+2) == '8')
  224.             nr_active++;
  225.         else
  226.             nr_inactive++;
  227.  
  228.         if (*(line+4) == 'b')
  229.             nr_changed++;
  230.     }
  231.  
  232.     {
  233.         char *s_inactive = "s";
  234.  
  235.         /*** check if 'tool' or 'tools' ***/
  236.         if (nr_inactive == 1)
  237.             s_inactive = "";
  238.  
  239.         /*** generate info text ***/
  240.         DoMethod(tx_info, MUIM_SetAsString, MUIA_Text_Contents,
  241.             eC ePB "%ld tool%s inactive · " ePW "%ld active · " eB ePB "%ld changed",
  242.             nr_inactive, s_inactive, nr_active, nr_changed);
  243.     }
  244. }
  245.  
  246.  
  247.  
  248.  
  249.  
  250. /*** disable gadgets & menus, show changes ***/
  251.  
  252. void check_entries(void)
  253. {
  254.     ULONG i, sel, c_pos;
  255.     UWORD nr_active = 0, nr_inactive = 0, nr_selected = 0;
  256.     char *line;
  257.  
  258.     BOOL disable_activate = TRUE, disable_toggle = TRUE;
  259.     BOOL disable_deactivate = TRUE, disable_restore = TRUE;
  260.     BOOL disable_perform = TRUE, disable_edit = TRUE;
  261.  
  262.     BOOL refresh_display = FALSE;
  263.  
  264.  
  265.     /*** cursor position ***/
  266.     get(lv_tools, MUIA_List_Active, &c_pos);
  267.  
  268.     /*** count ***/
  269.     for (i=0;; i++)
  270.     {
  271.         DoMethod(lv_tools, MUIM_List_GetEntry, i, &line);
  272.  
  273.         /*** last line ? ***/
  274.         if (!line)
  275.             break;
  276.  
  277.         /*** count selected or at cursor-position ***/
  278.         DoMethod(lv_tools, MUIM_List_Select, i, MUIV_List_Select_Ask, &sel);
  279.         if (sel || i==c_pos)
  280.         {
  281.             /*** count status of selected tools ***/
  282.             if (*(line+2)=='8')
  283.                 nr_active++;
  284.             else
  285.                 nr_inactive++;
  286.  
  287.             nr_selected++;
  288.         }
  289.  
  290.         /*** check difference between stored and new status ***/
  291.         if (*(line+2) != *line)
  292.         {
  293.             /*** make entry bold ***/
  294.             if (*(line+4)!='b')
  295.                 refresh_display = TRUE;
  296.             *(line+4)='b';
  297.  
  298.             disable_perform = FALSE;
  299.         }
  300.         else
  301.         {
  302.             /*** now a normal entry ***/
  303.             if (*(line+4)!='n')
  304.                 refresh_display = TRUE;
  305.             *(line+4)='n';
  306.         }
  307.     }
  308.  
  309.     if (nr_selected > 0)
  310.     {
  311.         disable_toggle = FALSE;
  312.         disable_restore = FALSE;
  313.  
  314.         if (nr_inactive)
  315.             disable_activate = FALSE;
  316.  
  317.         if (nr_active)
  318.             disable_deactivate = FALSE;
  319.     }
  320.  
  321.     if (nr_selected == 1)
  322.         disable_edit = FALSE;
  323.  
  324.  
  325.     /*** set status of gadgets ***/
  326.     set(bt_perform, MUIA_Disabled, disable_perform);
  327.  
  328.     set(bt_activate, MUIA_Disabled, disable_activate);
  329.     set(bt_toggle, MUIA_Disabled, disable_toggle);
  330.     set(bt_deactivate, MUIA_Disabled, disable_deactivate);
  331.     set(bt_edit, MUIA_Disabled, disable_edit);
  332.  
  333.  
  334.     /*** set status of menus ***/
  335.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_PERFORM, !disable_perform);
  336.  
  337.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_ACTIVATE, !disable_activate);
  338.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_DEACTIVATE, !disable_deactivate);
  339.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_TOGGLE, !disable_toggle);
  340.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_RESTORE, !disable_restore);
  341.  
  342.     DoMethod(wi_main, MUIM_Window_SetMenuState ,ID_EDIT, !disable_edit);
  343.  
  344.     /*** refresh display ***/
  345.     if (refresh_display)
  346.         DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  347. }
  348.  
  349.  
  350.  
  351.  
  352. /*** change status of tools ***/
  353.  
  354. void change_tools_list_entry(LONG pos, UWORD mode)
  355. {
  356.     char *line, *pen;
  357.  
  358.     /*** get entry ***/
  359.     DoMethod(lv_tools, MUIM_List_GetEntry, pos, &line);
  360.     pen = line+2;
  361.  
  362.     /*** change entry ***/
  363.     switch (mode)
  364.     {
  365.         case MODE_ACTIVATE:
  366.             *pen = '8';
  367.         break;
  368.  
  369.         case MODE_DEACTIVATE:
  370.             *pen = '2';
  371.         break;
  372.  
  373.         case MODE_TOGGLE:
  374.             if (*pen=='2')
  375.                 *pen = '8';
  376.             else
  377.                 *pen = '2';
  378.         break;
  379.  
  380.         case MODE_RESTORE:
  381.             *pen = *line;
  382.         break;
  383.     }
  384. }
  385.  
  386. void change_tools_list_entry_cursor(UWORD mode)
  387. {
  388.     LONG i;
  389.  
  390.     get(lv_tools, MUIA_List_Active, &i);
  391.  
  392.     if (i >= 0)
  393.     {
  394.         change_tools_list_entry(i, mode);
  395.         DoMethod(lv_tools, MUIM_List_Redraw, i);
  396.     }
  397. }
  398.  
  399. void change_tools_list(UWORD mode)
  400. {
  401.     ULONG end, i, nr=0;
  402.     ULONG sel;
  403.  
  404.     /*** get number of all entries ***/
  405.     get(lv_tools, MUIA_List_Entries, &end);
  406.  
  407.     set(lv_tools, MUIA_List_Quiet, TRUE);
  408.     for (i=0; i<end ; i++)
  409.     {
  410.         /*** entry selected ? ***/
  411.         DoMethod(lv_tools, MUIM_List_Select, i, MUIV_List_Select_Ask, &sel);
  412.         if (sel)
  413.         {
  414.             change_tools_list_entry(i, mode);
  415.             nr++;
  416.         }
  417.     }
  418.     set(lv_tools, MUIA_List_Quiet, FALSE);
  419.  
  420.     /*** refresh display, if almost one entry is selected ***/
  421.     if (nr>0)
  422.         DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  423.  
  424.     /*** change entry on cursor-position ***/
  425.     else
  426.         change_tools_list_entry_cursor(mode);
  427. }
  428.  
  429.  
  430.  
  431.  
  432. /*** select every entry of tools_list ***/
  433.  
  434. void select_tools_list(ULONG mode)
  435. {
  436.     ULONG end, i;
  437.     ULONG sel;
  438.  
  439.     /*** get number of all entries ***/
  440.     get(lv_tools, MUIA_List_Entries, &end);
  441.  
  442.     for (i=0; i<end ; i++)
  443.         DoMethod(lv_tools, MUIM_List_Select, i, mode, &sel);
  444.  
  445.     /*** refresh display ***/
  446.     DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  447. }
  448.  
  449.  
  450.  
  451.  
  452. /*** select tools of tools_list matching pattern ***/
  453.  
  454. void select_pattern_tools_list(char *pattern)
  455. {
  456.     ULONG end, i;
  457.     ULONG sel;
  458.     char *tool_name, *pattern_token;
  459.  
  460.     /*** alloc mem for pattern_name ***/
  461.     if (pattern_token = AllocMem(MAXNAMELEN, MEMF_ANY))
  462.     {
  463.         /*** tokenize pattern ***/
  464.         ParsePatternNoCase(pattern, pattern_token, MAXNAMELEN);
  465.  
  466.         /*** get number of all entries ***/
  467.         get(lv_tools, MUIA_List_Entries, &end);
  468.  
  469.         for (i=0; i<end ; i++)
  470.         {
  471.             DoMethod(lv_tools, MUIM_List_GetEntry, i, &tool_name);
  472.  
  473.             /*** check tool_name, if it fits on pattern ***/
  474.             if (MatchPatternNoCase(pattern_token, tool_name+5))
  475.                 DoMethod(lv_tools, MUIM_List_Select, i, MUIV_List_Select_On, &sel);
  476.         }
  477.  
  478.         /*** refresh display ***/
  479.         DoMethod(lv_tools, MUIM_List_Redraw, MUIV_List_Redraw_All);
  480.  
  481.         FreeMem(pattern_token, MAXNAMELEN);
  482.     }
  483. }
  484.  
  485.  
  486.  
  487.  
  488. /*** rename the tools in the wbstartup-directory ***/
  489.  
  490. void rename_tools_list(void)
  491. {
  492.     char *file_name, *new_file_name;
  493.  
  494.     /*** alloc mem for filenames ***/
  495.     if (file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  496.     {
  497.         if (new_file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  498.         {
  499.             char *line;
  500.             ULONG i;
  501.  
  502.             for (i=0; ; i++)
  503.             {
  504.                 DoMethod(lv_tools, MUIM_List_GetEntry, i, &line);
  505.  
  506.                 if (!line)
  507.                     break;
  508.  
  509.                 /*** check if old and new status different ***/
  510.                 if (*(line+4) == 'b')
  511.                 {
  512.  
  513.                     /*** turn status to active ***/
  514.                     if (*(line+2) == '8')
  515.                     {
  516.                         sprintf(file_name, "SYS:WBStartup/%s.noinfo", line+5);
  517.                         sprintf(new_file_name, "SYS:WBStartup/%s.info", line+5);
  518.                     }
  519.  
  520.                     /*** turn status to inactive ***/
  521.                     else
  522.                     {
  523.                         sprintf(file_name, "SYS:WBStartup/%s.info", line+5);
  524.                         sprintf(new_file_name, "SYS:WBStartup/%s.noinfo", line+5);
  525.                     }
  526.  
  527.                     if (rename(file_name, new_file_name))
  528.                         printf("Can't rename: '%s' -> '%s'\n", file_name, new_file_name);
  529.                 }
  530.             }
  531.             FreeMem(new_file_name, MAXNAMELEN);
  532.  
  533.         }
  534.         FreeMem(file_name, MAXNAMELEN);
  535.  
  536.     }
  537. }
  538.  
  539.  
  540.  
  541.  
  542. /*** string requester ***/
  543.  
  544. /*** open requester ***/
  545.  
  546. BOOL open_string_request(char *title_text, ULONG string_len)
  547. {
  548.     wi_string_request = WindowObject,
  549.         MUIA_Window_ID, MAKE_ID('S','R','E','Q'),
  550.         MUIA_Window_Title, "WbMan",
  551.         MUIA_Window_Menu, MUIV_Window_Menu_NoMenu,
  552.         WindowContents, VGroup,
  553.             Child, HGroup,
  554.                 GroupFrameT(title_text),
  555.                 Child, st_string = StringObject,
  556.                     StringFrame,
  557.                     MUIA_String_MaxLen, string_len,
  558.                     End,
  559.                 End,
  560.             Child, VSpace(2),
  561.             Child, HGroup,
  562.                 MUIA_Group_SameSize, TRUE,
  563.                 Child, bt_string_ok = SimpleButton("_OK"),
  564.                 Child, HSpace(0),
  565.                 Child, bt_string_cancel = SimpleButton("_Cancel"),
  566.                 End,
  567.             End,
  568.         End;
  569.  
  570.  
  571.     /*** string requester failed ? ***/
  572.     if (!wi_string_request)
  573.         fail(app, "Creating string-requester failed !");
  574.  
  575.  
  576.  
  577.     /*** connections & cycle ***/
  578.  
  579.     DoMethod(wi_string_request,    MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,        app,    2,    MUIM_Application_ReturnID,    ID_STRING_CANCEL    );
  580.  
  581.     DoMethod(bt_string_ok,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_STRING_OK        );
  582.     DoMethod(bt_string_cancel,    MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_STRING_CANCEL    );
  583.  
  584.     /*** activate ok-button if string is ready ***/
  585.     DoMethod(st_string,
  586.         MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  587.         wi_string_request, 3,
  588.         MUIM_Set, MUIA_Window_ActiveObject, bt_string_ok);
  589.  
  590.     DoMethod(wi_string_request, MUIM_Window_SetCycleChain,
  591.         st_string,
  592.         bt_string_ok, bt_string_cancel,
  593.         NULL);
  594.  
  595.  
  596.     /*** add & open window ***/
  597.  
  598.     DoMethod(app, OM_ADDMEMBER, wi_string_request);
  599.     set(wi_string_request, MUIA_Window_Open            , TRUE);
  600.     set(wi_string_request, MUIA_Window_ActiveObject    , st_string);
  601.  
  602.     return(TRUE);
  603. }
  604.  
  605.  
  606. /*** close requester ***/
  607.  
  608. void close_string_request(void)
  609. {
  610.     /*** close & remove window ***/
  611.     set(wi_string_request, MUIA_Window_Open, FALSE);
  612.     DoMethod(app, OM_REMMEMBER, wi_string_request);
  613.     MUI_DisposeObject(wi_string_request);
  614.  
  615.     /*** wake up main-window ***/
  616.     set(wi_main, MUIA_Window_Sleep, FALSE);
  617. }
  618.  
  619.  
  620.  
  621.  
  622. /*** edit tooltypes ***/
  623.  
  624. /*** open edit-window ***/
  625.  
  626. BOOL open_edit_window(struct DiskObject *dobj, char *name)
  627. {
  628.     wi_edit = WindowObject,
  629.         MUIA_Window_ID, MAKE_ID('E','D','I','T'),
  630.         MUIA_Window_Title, "WbMan",
  631.         MUIA_Window_Menu, MUIV_Window_Menu_NoMenu,
  632.         WindowContents, VGroup,
  633.             Child, HGroup,
  634.                 TextFrame,
  635.                 InnerSpacing(4,3),
  636.                 Child, ImageObject,
  637.                     MUIA_Image_OldImage, dobj->do_Gadget.GadgetRender,
  638.                     End,
  639.                 Child, VGroup,
  640.                     Child, VSpace(0),
  641.                     Child, tx_edit = TextObject,
  642.                         MUIA_Text_PreParse, eC,
  643.                         MUIA_Text_Contents, name,
  644.                         MUIA_Text_SetMin, TRUE,
  645.                         End,
  646.                     Child, VSpace(0),
  647.                     End,
  648.                 Child, ImageObject,
  649.                     MUIA_Image_OldImage, dobj->do_Gadget.GadgetRender,
  650.                     End,
  651.                 End,
  652.             Child, VGroup,
  653.                 GroupFrameT("ToolTypes"),
  654.                 Child, VGroup,
  655.                     GroupSpacing(0),
  656.                     Child, lv_edit = ListviewObject,
  657.                         MUIA_Listview_Input, TRUE,
  658.                         MUIA_Listview_List, ListObject,
  659.                             InputListFrame,
  660.                             MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
  661.                             MUIA_List_DestructHook, MUIV_List_DestructHook_String,
  662.                             End,
  663.                         End,
  664.                     Child, HGroup,
  665.                         GroupSpacing(0),
  666.                         Child, bt_edit_new = SimpleButton("_New"),
  667.                         Child, bt_edit_copy = SimpleButton("Cop_y"),
  668.                         Child, bt_edit_remove = SimpleButton("_Remove"),
  669.                         End,
  670.                     Child, HGroup,
  671.                         GroupSpacing(0),
  672.                         Child, bt_edit_activate = SimpleButton("_Activate"),
  673.                         Child, bt_edit_deactivate = SimpleButton("_Deactivate"),
  674.                         End,
  675.                     Child, st_edit_string = StringObject,
  676.                         StringFrame,
  677.                         End,
  678.                     End,
  679.                 End,
  680.             Child, HGroup,
  681.                 Child, Label2("Default Tool:"),
  682.                 Child, st_edit_default = String(NULL, MAXNAMELEN),
  683.                 End,
  684.             Child, VSpace(2),
  685.             Child, HGroup,
  686.                 MUIA_Group_SameSize, TRUE,
  687.                 Child, bt_edit_save = SimpleButton("_Save"),
  688.                 Child, HSpace(0),
  689.                 Child, bt_edit_cancel = SimpleButton("_Cancel"),
  690.                 End,
  691.             End,
  692.         End;
  693.  
  694.  
  695.     /*** window failed ? ***/
  696.     if (!wi_edit)
  697.         fail(app, "Creating edit-window failed !");
  698.  
  699.  
  700.     /*** connections & cycle ***/
  701.  
  702.     DoMethod(wi_edit,                MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_CANCEL        );
  703.  
  704.     DoMethod(bt_edit_new,            MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_NEW            );
  705.     DoMethod(bt_edit_copy,            MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_COPY        );
  706.     DoMethod(bt_edit_remove,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_REMOVE        );
  707.  
  708.     DoMethod(bt_edit_activate,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_ACTIVATE    );
  709.     DoMethod(bt_edit_deactivate,    MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_DEACTIVATE    );
  710.  
  711.     DoMethod(bt_edit_save,            MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_SAVE        );
  712.     DoMethod(bt_edit_cancel,        MUIM_Notify,    MUIA_Pressed,                FALSE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_CANCEL        );
  713.  
  714.     DoMethod(lv_edit,                MUIM_Notify,    MUIA_Listview_SelectChange,    TRUE,        app,    2,    MUIM_Application_ReturnID,    ID_EDIT_LV_ACTIVE    );
  715.  
  716.     set(lv_edit, MUIA_List_Active, MUIV_List_Active_Top);
  717.     DoMethod(lv_edit,
  718.         MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  719.         app, 2,
  720.         MUIM_Application_ReturnID, ID_EDIT_LV_ACTIVE);
  721.  
  722.     set(st_edit_string, MUIA_String_AttachedList, lv_edit);
  723.     DoMethod(st_edit_string,
  724.         MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
  725.         app, 2,
  726.         MUIM_Application_ReturnID,  ID_EDIT_ST_READY);
  727.  
  728.     DoMethod(wi_edit, MUIM_Window_SetCycleChain,
  729.         st_edit_string,
  730.         bt_edit_new, bt_edit_copy, bt_edit_remove,
  731.         st_edit_default,
  732.         bt_edit_save, bt_edit_cancel,
  733.         NULL);
  734.  
  735.  
  736.     /*** add & open window ***/
  737.     DoMethod(app, OM_ADDMEMBER, wi_edit);
  738.     set(wi_edit, MUIA_Window_Open, TRUE);
  739.     set(wi_edit, MUIA_Window_ActiveObject, st_edit_string);
  740.  
  741.     return(TRUE);
  742. }
  743.  
  744.  
  745. /*** close edit-window ***/
  746.  
  747. void close_edit_window(void)
  748. {
  749.     /*** close & remove window ***/
  750.     set(wi_edit, MUIA_Window_Open, FALSE);
  751.     DoMethod(app, OM_REMMEMBER, wi_edit);
  752.     MUI_DisposeObject(wi_edit);
  753.  
  754.     if (disk_object)
  755.         FreeDiskObject(disk_object);
  756.  
  757.     /*** wake up main-window ***/
  758.     set(wi_main, MUIA_Window_Sleep, FALSE);
  759. }
  760.  
  761.  
  762. /*** disable gadgets ***/
  763.  
  764. void check_edit_entries(void)
  765. {
  766.     LONG pos;
  767.     char *line;
  768.  
  769.     BOOL disable_cursor = TRUE;
  770.     BOOL disable_activate = TRUE, disable_deactivate = TRUE;
  771.  
  772.  
  773.     /*** cursor position ***/
  774.     get(lv_edit, MUIA_List_Active, &pos);
  775.  
  776.     if (pos >= 0)
  777.     {
  778.         disable_cursor = FALSE;
  779.  
  780.         /*** get active line ***/
  781.         DoMethod(lv_edit, MUIM_List_GetEntry, pos, &line);
  782.  
  783.         /*** check if there are brakets -> inactive ***/
  784.         if (*line == '(' && *(line + strlen(line) - 1) == ')')
  785.             disable_activate = FALSE;
  786.         else
  787.             disable_deactivate = FALSE;
  788.     }
  789.  
  790.     set(bt_edit_copy, MUIA_Disabled, disable_cursor);
  791.     set(bt_edit_remove, MUIA_Disabled, disable_cursor);
  792.     set(st_edit_string, MUIA_Disabled, disable_cursor);
  793.  
  794.     set(bt_edit_activate, MUIA_Disabled, disable_activate);
  795.     set(bt_edit_deactivate, MUIA_Disabled, disable_deactivate);
  796.  
  797.     /*** clear string if disabled ***/
  798.     if (disable_cursor)
  799.         set(st_edit_string, MUIA_String_Contents, "");
  800.  
  801. }
  802.  
  803.  
  804. /*** edit the active tool ***/
  805.  
  806. void edit_tooltypes_diskobject(struct DiskObject *dobj, char *fn)
  807. {
  808.     char **tt;
  809.  
  810.     /*** open window ***/
  811.     if (open_edit_window(dobj, fn))
  812.     {
  813.         tt = dobj->do_ToolTypes;
  814.  
  815.         /*** copy tooltype-array into listview ***/
  816.         while (tt && *tt)
  817.             DoMethod(lv_edit, MUIM_List_Insert, tt++, 1, MUIV_List_Insert_Bottom);
  818.  
  819.         /*** fill in strings ***/
  820.         set(st_edit_default, MUIA_String_Contents, dobj->do_DefaultTool);
  821.         set(lv_edit, MUIA_List_Active, MUIV_List_Active_Top);
  822.     }
  823. }
  824.  
  825. void edit_tooltypes_entry(void)
  826. {
  827.     char *file_name;
  828.  
  829.     if (file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  830.     {
  831.         char *line;
  832.  
  833.         /*** get entry ***/
  834.         DoMethod(lv_tools, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &line);
  835.  
  836.         sprintf(file_name, "SYS:WBStartup/%s", line+5);
  837.  
  838.         if (disk_object = GetDiskObject(file_name))
  839.         {
  840.             temp_dobj_flag = FALSE;
  841.             edit_tooltypes_diskobject(disk_object, line+5);
  842.         }
  843.         else
  844.         {
  845.             /*** is tool inactive ? create temporary .info-file ***/
  846.             temp_dobj_flag = TRUE;
  847.             sprintf(file_name, "copy SYS:WBStartup/%s.noinfo T:WbMan_Temp.info", line+5);
  848.             if (Execute(file_name, NULL, NULL) &&
  849.                 (disk_object = GetDiskObjectNew("T:WbMan_Temp"))
  850.                 )
  851.                 edit_tooltypes_diskobject(disk_object, line+5);
  852.             else
  853.             {
  854.             }
  855.         }
  856.  
  857.         check_edit_entries();
  858.  
  859.         FreeMem(file_name, MAXNAMELEN);
  860.     }
  861. }
  862.  
  863. void save_tooltypes(void)
  864. {
  865.     if (disk_object)
  866.     {
  867.         char *file_name;
  868.  
  869.         if (file_name = AllocMem(MAXNAMELEN, MEMF_ANY))
  870.         {
  871.             char *old_def_tool;
  872.             char **old_tooltypes;
  873.             char *line;
  874.             ULONG nr;
  875.             char **new_tooltypes;
  876.  
  877.             /*** store actual data ***/
  878.             old_def_tool = disk_object->do_DefaultTool;
  879.             old_tooltypes = disk_object->do_ToolTypes;
  880.  
  881.             /*** new data ***/
  882.             get(st_edit_default, MUIA_String_Contents, &line);
  883.             disk_object->do_DefaultTool = line;
  884.  
  885.             /*** generate array of tooltypes ***/
  886.             get(lv_edit, MUIA_List_Entries, &nr);
  887.             if (new_tooltypes = AllocMem((nr+1) << 2, MEMF_ANY))
  888.             {
  889.                 char **l;
  890.                 ULONG i;
  891.  
  892.                 l = new_tooltypes;
  893.                 for (i=0; ; i++)
  894.                 {
  895.                     DoMethod(lv_edit, MUIM_List_GetEntry, i, &line);
  896.  
  897.                     /*** last line ? ***/
  898.                     if (!line)
  899.                         break;
  900.  
  901.                     *l++ = line;
  902.                 }
  903.                 /*** terminate array ***/
  904.                 *l = NULL;
  905.  
  906.                 /*** new_data ***/
  907.                 disk_object->do_ToolTypes = new_tooltypes;
  908.  
  909.                 /*** get entry ***/
  910.                 DoMethod(lv_tools, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &line);
  911.  
  912.                 if (temp_dobj_flag)
  913.                 {
  914.                     PutDiskObject("T:WbMan_Temp", disk_object);
  915.  
  916.                     sprintf(file_name, "copy T:WbMan_Temp.info SYS:WBStartup/%s.noinfo", line+5);
  917.                     Execute(file_name, NULL, NULL);
  918.                 }
  919.                 else
  920.                 {
  921.                     /*** get disk object ***/
  922.                     sprintf(file_name, "SYS:WBStartup/%s", line+5);
  923.  
  924.                     PutDiskObject(file_name, disk_object);
  925.                 }
  926.  
  927.                 FreeMem(new_tooltypes, (nr+1) << 2);
  928.             }
  929.  
  930.             /*** restore data ***/
  931.             disk_object->do_DefaultTool = old_def_tool;
  932.             disk_object->do_ToolTypes = old_tooltypes;
  933.  
  934.             FreeMem(file_name, MAXNAMELEN);
  935.         }
  936.     }
  937. }
  938.  
  939.  
  940.  
  941.  
  942. /*** image-stuff ***/
  943.  
  944. static UWORD wbman_sleep_img1_data[] = {
  945.     0x0003,0xc000,0x0000,0x0000,0x0004,0x4000,0x0000,0x0000,
  946.     0x0008,0x4000,0x0000,0x0000,0x0018,0x4de0,0x0000,0x0000,
  947.     0x0020,0x3210,0x0000,0x0000,0x0020,0x0008,0x0000,0x0000,
  948.     0x0020,0x0008,0x0000,0x0000,0x0020,0xf008,0x0000,0x0000,
  949.     0x0020,0x2788,0x0000,0x0000,0x0010,0x4108,0x0000,0x0000,
  950.     0x0010,0xf208,0x0000,0x0000,0x0008,0x0790,0x0000,0x0000,
  951.     0x0008,0x0020,0x0000,0x0000,0x003c,0x00c0,0x0000,0x0400,
  952.     0x0046,0x3f00,0x0000,0x0c00,0x0083,0xe000,0x0000,0x0c00,
  953.     0x0100,0x8004,0x0000,0x2c00,0x0101,0x001c,0x0000,0x2c00,
  954.     0x0386,0x007e,0x0000,0x2c00,0x04c8,0x01fe,0x0001,0x2c00,
  955.     0x08b0,0x07f8,0x0001,0x2c00,0x0500,0x1fe0,0x0001,0x2c00,
  956.     0x0200,0x7f80,0x0009,0x2c00,0x0001,0xfe00,0x0009,0x2c00,
  957.     0x0007,0xf8f8,0x2009,0x2c00,0x001f,0xe1cc,0x7009,0x2c00,
  958.     0x007f,0x8038,0x7009,0xcc00,0x01fe,0x0070,0x2009,0x0c00,
  959.     0x01f8,0x0000,0x0009,0x0c00,0x00e0,0x0070,0x700e,0x0c00,
  960.     0x0080,0x0000,0x0008,0x0c00,0x0000,0x0000,0x0008,0x0c00,
  961.     0x0000,0x3fff,0xfff0,0x0c00,0x0000,0x0000,0x0000,0x0c00,
  962.     0x7fff,0xffff,0xffff,0xfc00,0x0003,0xc000,0x0000,0x0000,
  963.     0x0007,0xc000,0x0000,0x0000,0x000f,0xc000,0x0000,0x0000,
  964.     0x001f,0xcde0,0x0000,0x0000,0x003f,0xfff0,0x0000,0x0000,
  965.     0x003f,0xfff8,0x0000,0x0000,0x003f,0xfff8,0x0000,0x0000,
  966.     0x003f,0x0ff8,0x0000,0x0000,0x003f,0xd878,0x0000,0x0000,
  967.     0x001f,0xbef8,0x0000,0x0000,0x001f,0x0df8,0x0000,0x0000,
  968.     0x000f,0xf870,0x0000,0x0000,0x000f,0xffe0,0x0000,0x0000,
  969.     0xffff,0xffff,0xffff,0xf800,0xd57f,0xff54,0x1555,0x5000,
  970.     0xd5ff,0xf5f8,0xcfff,0xd000,0xd5ff,0xd7e7,0xefff,0x9000,
  971.     0xd5ff,0x5713,0xcaa9,0x1000,0xd7ff,0x5e41,0x1ffe,0x1000,
  972.     0xd7fd,0x5902,0x7ffc,0x1000,0xdff5,0x4409,0x5548,0x1000,
  973.     0xd755,0x1027,0xfff0,0x1000,0xd754,0x409f,0xffe0,0x1000,
  974.     0xd551,0x022a,0xaa40,0x1000,0xd544,0x0802,0x8a80,0x1000,
  975.     0xd510,0x2222,0x8a80,0x9000,0xd440,0x8a82,0x8a80,0x3000,
  976.     0xd102,0x6a8a,0x8a80,0x5000,0xc209,0xeaaa,0xaa84,0x5000,
  977.     0xcf25,0xea8a,0x8a81,0x5000,0xdf95,0xf2aa,0xaa45,0x5000,
  978.     0xcc55,0xe000,0x0025,0x5000,0xc155,0xc000,0x000d,0x5000,
  979.     0xd555,0x5555,0x5555,0x5000,0x8000,0x0000,0x0000,0x0000,
  980.  
  981. };
  982.  
  983. static struct Image wbman_sleep_img1 = {
  984.     0x0000,0x0000,0x0036,0x0023,0x0002,
  985.     &wbman_sleep_img1_data[0],
  986.     0x03,0x00,0x00000000,
  987. };
  988.  
  989. static struct DiskObject wbman_sleep_dobj = {
  990.     0xe310,0x0001,
  991.     0x00000000,
  992.     0x00a9,0x00fa,0x0036,0x0024,0x0005,0x0001,0x95a5,
  993.     (APTR)&wbman_sleep_img1,NULL,
  994.     0x00000000,0x00000000,0x00000000,
  995.     0x0064,
  996.     0x00000000,
  997.     0x0003,
  998.     0x00000000,0x00000000,0x000000a5,0x000000e5,
  999.     0x00000000,0x00000000,0x00001000,
  1000. };
  1001.  
  1002.  
  1003.  
  1004.  
  1005. /*** mui-stuff ***/
  1006.  
  1007. /*** list hooks ***/
  1008.  
  1009. SAVEDS ASM char *tools_list_confunc(
  1010.     REG(a0) struct Hook *hook,
  1011.     REG(a2) APTR mem_pool,
  1012.     REG(a1) struct FileInfoBlock *fib)
  1013. {
  1014.     char active_pattern[14];
  1015.     char inactive_pattern[20];
  1016.  
  1017.     /*** tokenize pattern ***/
  1018.     ParsePatternNoCase("#?.info", active_pattern, 14);
  1019.     ParsePatternNoCase("#?.noinfo", inactive_pattern, 20);
  1020.  
  1021.     /*** check, only files ***/
  1022.     if (fib->fib_DirEntryType < 0)
  1023.     {
  1024.         char *file_name, *entry;
  1025.  
  1026.         if (entry = AllocMem(MAXNAMELEN, MEMF_ANY))
  1027.         {
  1028.             file_name = &fib->fib_FileName[0];
  1029.  
  1030.             /*** check if active ***/
  1031.             if (MatchPatternNoCase(active_pattern, file_name))
  1032.             {
  1033.                 /*** cut the ".info" at end ***/
  1034.                 *(file_name + strlen(file_name) - 5) = 0;
  1035.  
  1036.                 /*** valid filename ? ***/
  1037.                 if (check_tool_name(file_name))
  1038.                 {
  1039.                     sprintf(entry, "8" ePW eN "%s", file_name);
  1040.                     return(entry);
  1041.                 }
  1042.             }
  1043.  
  1044.             /*** or inactive ***/
  1045.             else if (MatchPatternNoCase(inactive_pattern, file_name))
  1046.             {
  1047.                 /*** cut the ".noinfo" at end ***/
  1048.                 *(file_name + strlen(file_name) - 7) = 0;
  1049.  
  1050.                 /*** valid filename ? ***/
  1051.                 if (check_tool_name(file_name))
  1052.                 {
  1053.                     sprintf(entry, "2" ePB eN "%s", file_name);
  1054.                     return(entry);
  1055.                 }
  1056.             }
  1057.  
  1058.             FreeMem(entry, MAXNAMELEN);
  1059.         }
  1060.     }
  1061.  
  1062.     /*** insert nothing ***/
  1063.     return(0);
  1064. }
  1065.  
  1066. static struct Hook tools_list_conhook = {
  1067.     {NULL, NULL},
  1068.     (void *)tools_list_confunc,
  1069.     NULL, NULL
  1070. };
  1071.  
  1072.  
  1073. SAVEDS ASM LONG tools_list_desfunc(
  1074.     REG(a0) struct Hook *hook,
  1075.     REG(a2) APTR mem_pool,
  1076.     REG(a1) char *line)
  1077. {
  1078.     FreeMem(line, MAXNAMELEN);
  1079.  
  1080.     return(0);
  1081. }
  1082.  
  1083. static struct Hook tools_list_deshook = {
  1084.     {NULL, NULL},
  1085.     (void *)tools_list_desfunc,
  1086.     NULL, NULL
  1087. };
  1088.  
  1089.  
  1090. SAVEDS ASM LONG tools_list_dspfunc(
  1091.     REG(a0) struct Hook *hook,
  1092.     REG(a2) char **array,
  1093.     REG(a1) char *line)
  1094. {
  1095.     *array = line+1;
  1096.     return(0);
  1097. }
  1098.  
  1099. static struct Hook tools_list_dsphook = {
  1100.     {NULL, NULL},
  1101.     (void *)tools_list_dspfunc,
  1102.     NULL, NULL
  1103. };
  1104.  
  1105.  
  1106. SAVEDS ASM LONG tools_list_cmpfunc(
  1107.     REG(a0) struct Hook *hook,
  1108.     REG(a2) char *line1,
  1109.     REG(a1) char *line2)
  1110. {
  1111.     return(stricmp(line2+5, line1+5));
  1112. }
  1113.  
  1114. static struct Hook tools_list_cmphook = {
  1115.     {NULL, NULL},
  1116.     (void *)tools_list_cmpfunc,
  1117.     NULL, NULL
  1118. };
  1119.  
  1120.  
  1121.  
  1122. /*** arexx hooks ***/
  1123.  
  1124. SAVEDS ASM APTR select_rxfunc(
  1125.     REG(a0) struct Hook *hook,
  1126.     REG(a2) Object *appl,
  1127.     REG(a1) ULONG *arg)
  1128. {
  1129.     char *pattern;
  1130.  
  1131.     /*** pattern valid ? ***/
  1132.     if (pattern = (char *)*arg)
  1133.     {
  1134.         /*** clear list & select matching pattern ***/
  1135.         select_tools_list(MUIV_List_Select_Off);
  1136.         select_pattern_tools_list(pattern);
  1137.     }
  1138.  
  1139.     return(RETURN_OK);
  1140. }
  1141.  
  1142. static const struct Hook select_rxhook = {
  1143.     {NULL, NULL},
  1144.     (void *)select_rxfunc,
  1145.     NULL,NULL
  1146. };
  1147.  
  1148.  
  1149.  
  1150.  
  1151. /*** arexx list ***/
  1152.  
  1153. static struct MUI_Command arexx_list[] =
  1154. {
  1155.     {"rescan",        MC_TEMPLATE_ID,        ID_RESCAN,        NULL},
  1156.  
  1157.     {"select",        "PATTERN/A",        1,                &select_rxhook},
  1158.  
  1159.     {"activate",    MC_TEMPLATE_ID,        ID_ACTIVATE,    NULL},
  1160.     {"deactivate",    MC_TEMPLATE_ID,        ID_DEACTIVATE,    NULL},
  1161.     {"toggle",        MC_TEMPLATE_ID,        ID_TOGGLE,        NULL},
  1162.     {"restore",        MC_TEMPLATE_ID,        ID_RESTORE,        NULL},
  1163.  
  1164.     {NULL,            NULL,                0,                NULL}
  1165. };
  1166.  
  1167.  
  1168.  
  1169. /*** menu ***/
  1170.  
  1171. static const struct NewMenu menu_list[] =
  1172. {
  1173.     { NM_TITLE,    "Project",            0,    0,    0,    0                            },
  1174.  
  1175.     { NM_ITEM,    "About...",            "?",0,    0,    (APTR) ID_ABOUT                },
  1176.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1177.     { NM_ITEM,    "Rescan",            "S",0,    0,    (APTR) ID_RESCAN            },
  1178.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1179.     { NM_ITEM,    "Perform",            "P",0,    0,    (APTR) ID_PERFORM            },
  1180.     { NM_ITEM,    "Quit",                "Q",0,    0,    (APTR) ID_QUIT                },
  1181.  
  1182.  
  1183.     { NM_TITLE,    "Tools",            0,    0,    0,    0                            },
  1184.  
  1185.     { NM_ITEM,    "Select All",        "A",0,    0,    (APTR) ID_SELECT_ALL        },
  1186.     { NM_ITEM,    "Select None",        "N",0,    0,    (APTR) ID_SELECT_NONE        },
  1187.     { NM_ITEM,    "Select Pattern",    "E",0,    0,    (APTR) ID_SELECT_PATTERN    },
  1188.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1189.     { NM_ITEM,    "Activate",            "V",0,    0,    (APTR) ID_ACTIVATE            },
  1190.     { NM_ITEM,    "Deactivate",        "D",0,    0,    (APTR) ID_DEACTIVATE        },
  1191.     { NM_ITEM,    "Toggle",            "T",0,    0,    (APTR) ID_TOGGLE            },
  1192.     { NM_ITEM,    "Restore",            "R",0,    0,    (APTR) ID_RESTORE            },
  1193.     { NM_ITEM,    NM_BARLABEL,        0,    0,    0,    0                            },
  1194.     { NM_ITEM,    "Edit Tooltypes",    "O",0,    0,    (APTR) ID_EDIT                },
  1195.  
  1196.  
  1197.     { NM_END,    NULL,                0,    0,    0,    0                            },
  1198. };
  1199.  
  1200.  
  1201.  
  1202.  
  1203. /*** main ***/
  1204.  
  1205. int main(int argc, char *argv[])
  1206. {
  1207.     /*** init ***/
  1208.     BOOL not_end = TRUE;
  1209.  
  1210.     init();
  1211.  
  1212.  
  1213.     /*** create mui-application ***/
  1214.     app = ApplicationObject,
  1215.         MUIA_Application_Title,                "WbMan",
  1216.         MUIA_Application_Version,            "$VER: WbMan 0.42 (27.8.93)",
  1217.         MUIA_Application_Copyright,            "© 1993 by kMel, Klaus Melchior",
  1218.         MUIA_Application_Author,            "Klaus Melchior",
  1219.         MUIA_Application_Description,        "Manages the WBStartup",
  1220.         MUIA_Application_Base,                "WBMAN",
  1221.         MUIA_Application_Menu,                menu_list,
  1222.         MUIA_Application_Commands,            arexx_list,
  1223.         MUIA_Application_SingleTask,        TRUE,
  1224.         MUIA_Application_DiskObject,        &wbman_sleep_dobj,
  1225.  
  1226.         SubWindow, wi_main = WindowObject,
  1227.             MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  1228.             MUIA_Window_Title, "WbMan",
  1229.             WindowContents, VGroup,
  1230.                 Child, VGroup,
  1231.                     Child, tx_info = TextObject,
  1232.                         TextFrame,
  1233.                         MUIA_Background, MUII_TextBack,
  1234.                         End,
  1235.                     Child, VGroup,
  1236.                         GroupSpacing(0),
  1237.                         Child, lv_tools = ListviewObject,
  1238.                             MUIA_Listview_MultiSelect, TRUE,
  1239.                             MUIA_Listview_DoubleClick, TRUE,
  1240.                             MUIA_Listview_List, ListObject,
  1241.                                 InputListFrame,
  1242.                                 MUIA_List_ConstructHook, &tools_list_conhook,
  1243.                                 MUIA_List_DestructHook, &tools_list_deshook,
  1244.                                 MUIA_List_CompareHook, &tools_list_cmphook,
  1245.                                 MUIA_List_DisplayHook, &tools_list_dsphook,
  1246.                                 End,
  1247.                             End,
  1248.                         Child, HGroup,
  1249.                             GroupSpacing(0),
  1250.                             Child, bt_activate        = SimpleButton("_Activate"),
  1251.                             Child, bt_toggle        = SimpleButton("_Toggle"),
  1252.                             Child, bt_deactivate    = SimpleButton("_Deactivate"),
  1253.                             End,
  1254.                         Child, HGroup,
  1255.                             GroupSpacing(0),
  1256.                             Child, bt_edit            = SimpleButton("_Edit Tooltypes"),
  1257.                             End,
  1258.                         End,
  1259.                     End,
  1260.                 Child, VSpace(2),
  1261.                 Child, HGroup,
  1262.                     MUIA_Group_SameSize, TRUE,
  1263.                     Child, bt_perform = SimpleButton("_Perform"),
  1264.                     Child, HSpace(0),
  1265.                     Child, bt_quit = SimpleButton("_Quit"),
  1266.                     End,
  1267.                 End,
  1268.             End,
  1269.         End;
  1270.  
  1271.  
  1272.     /*** application failed ? ***/
  1273.     if (!app)
  1274.         fail(app, "Creating application failed !");
  1275.  
  1276.     /*** connections & cycle ***/
  1277.     DoMethod(wi_main,        MUIM_Notify,    MUIA_Window_CloseRequest,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_QUIT            );
  1278.  
  1279.     DoMethod(bt_activate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_ACTIVATE        );
  1280.     DoMethod(bt_toggle,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_TOGGLE        );
  1281.     DoMethod(bt_deactivate,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_DEACTIVATE    );
  1282.     DoMethod(bt_edit,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_EDIT            );
  1283.  
  1284.     DoMethod(bt_perform,    MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_PERFORM        );
  1285.     DoMethod(bt_quit,        MUIM_Notify,    MUIA_Pressed,                FALSE,    app,    2,    MUIM_Application_ReturnID,    ID_QUIT            );
  1286.  
  1287.     DoMethod(lv_tools,        MUIM_Notify,    MUIA_Listview_DoubleClick,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_EDIT            );
  1288.     DoMethod(lv_tools,        MUIM_Notify,    MUIA_Listview_SelectChange,    TRUE,    app,    2,    MUIM_Application_ReturnID,    ID_LV_ACTIVE    );
  1289.  
  1290.     DoMethod(lv_tools, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  1291.         app, 2,
  1292.         MUIM_Application_ReturnID, ID_LV_ACTIVE);
  1293.  
  1294.     DoMethod(wi_main,        MUIM_Window_SetCycleChain,
  1295.         lv_tools,
  1296.         bt_activate, bt_toggle, bt_deactivate,
  1297.         bt_perform, bt_quit,
  1298.         NULL);
  1299.  
  1300.  
  1301.     /*** open window ***/
  1302.     set(wi_main, MUIA_Window_Open,            TRUE);
  1303.     set(wi_main, MUIA_Window_DefaultObject,    lv_tools);
  1304.  
  1305.  
  1306.     /*** get files ***/
  1307.     rescan_tools_list();
  1308.     count_tools_list();
  1309.  
  1310.     /*** set cursor on listview & check disable gadget ***/
  1311.     check_entries();
  1312.  
  1313.     /*** main-loop ***/
  1314.     while (not_end)
  1315.     {
  1316.         ULONG signal, id;
  1317.         ULONG pos;
  1318.         char *line;
  1319.  
  1320.         switch (id = DoMethod(app, MUIM_Application_Input, &signal))
  1321.         {
  1322.             case ID_ABOUT:
  1323.                 MUI_Request(app, wi_main, 0, NULL, "OK",
  1324.                     eC ePW "WbMan\n\n"
  1325.                     ePB "WbMan 0.41 (13.8.93)\n"
  1326.                     "Copyright 1993 by kMel, Klaus Melchior.\n"
  1327.                     "\nThis is a MUI-Application.\n"
  1328.                     "MUI is copyrighted by Stefan Stuntz.",
  1329.                     TAG_END);
  1330.             break;
  1331.  
  1332.             case MUIV_Application_ReturnID_Quit:
  1333.             case ID_QUIT:
  1334.                 not_end = FALSE;
  1335.             break;
  1336.  
  1337.             case ID_PERFORM:
  1338.                 rename_tools_list();
  1339.                 not_end = FALSE;
  1340.             break;
  1341.  
  1342.  
  1343.             case ID_EDIT:
  1344.                 if (!edit_window_open)
  1345.                 {
  1346.                     edit_window_open = TRUE;
  1347.  
  1348.                     /*** main-window must sleep now ***/
  1349.                     set(wi_main, MUIA_Window_Sleep, TRUE);
  1350.  
  1351.                     edit_tooltypes_entry();
  1352.                 }
  1353.             break;
  1354.  
  1355.             case ID_LV_ACTIVE:
  1356.                 check_entries();
  1357.             break;
  1358.  
  1359.  
  1360.             case ID_RESCAN:
  1361.                 rescan_tools_list();
  1362.                 check_entries();
  1363.                 count_tools_list();
  1364.             break;
  1365.  
  1366.             case ID_ACTIVATE:
  1367.                 change_tools_list(MODE_ACTIVATE);
  1368.                 check_entries();
  1369.                 count_tools_list();
  1370.             break;
  1371.  
  1372.             case ID_DEACTIVATE:
  1373.                 change_tools_list(MODE_DEACTIVATE);
  1374.                 check_entries();
  1375.                 count_tools_list();
  1376.             break;
  1377.  
  1378.             case ID_TOGGLE:
  1379.                 change_tools_list(MODE_TOGGLE);
  1380.                 check_entries();
  1381.                 count_tools_list();
  1382.             break;
  1383.  
  1384.             case ID_RESTORE:
  1385.                 change_tools_list(MODE_RESTORE);
  1386.                 check_entries();
  1387.                 count_tools_list();
  1388.             break;
  1389.  
  1390.  
  1391.             /*** pattern window ***/
  1392.  
  1393.             case ID_SELECT_ALL:
  1394.                 select_tools_list(MUIV_List_Select_On);
  1395.                 check_entries();
  1396.             break;
  1397.  
  1398.             case ID_SELECT_NONE:
  1399.                 select_tools_list(MUIV_List_Select_Off);
  1400.                 check_entries();
  1401.             break;
  1402.  
  1403.             case ID_SELECT_PATTERN:
  1404.                 if (!string_request_open)
  1405.                 {
  1406.                     string_request_open = TRUE;
  1407.  
  1408.                     /*** main-window must sleep now ***/
  1409.                     set(wi_main, MUIA_Window_Sleep, TRUE);
  1410.  
  1411.                     open_string_request("Pattern", 127);
  1412.                 }
  1413.             break;
  1414.  
  1415.  
  1416.             case ID_STRING_OK:
  1417.                 /*** get pattern ***/
  1418.                 get(st_string, MUIA_String_Contents, &line);
  1419.  
  1420.                 /*** clear list & select matching pattern ***/
  1421.                 select_tools_list(MUIV_List_Select_Off);
  1422.                 select_pattern_tools_list(line);
  1423.  
  1424.                 close_string_request();
  1425.                 string_request_open = FALSE;
  1426.                 check_entries();
  1427.             break;
  1428.  
  1429.             case ID_STRING_CANCEL:
  1430.                 close_string_request();
  1431.                 string_request_open = FALSE;
  1432.             break;
  1433.  
  1434.  
  1435.  
  1436.             /*** edit window ***/
  1437.  
  1438.             case ID_EDIT_LV_ACTIVE:
  1439.                 /*** copy active line into string ***/
  1440.                 DoMethod(lv_edit, MUIM_List_GetEntry, MUIV_List_GetEntry_Active, &line);
  1441.                 set(st_edit_string, MUIA_String_Contents, line);
  1442.                 check_edit_entries();
  1443.                 set(wi_edit, MUIA_Window_ActiveObject, st_edit_string);
  1444.             break;
  1445.  
  1446.  
  1447.             case ID_EDIT_NEW:
  1448.                 line = ">> new <<";
  1449.  
  1450.                 /*** insert at cursor-position ***/
  1451.                 get(lv_edit, MUIA_List_Active, &pos);
  1452.                 if (pos == -1)
  1453.                     pos = 0;
  1454.                 DoMethod(lv_edit, MUIM_List_Insert, &line, 1, pos);
  1455.                 set(lv_edit, MUIA_List_Active, pos);
  1456.  
  1457.                 check_edit_entries();
  1458.             break;
  1459.  
  1460.             case ID_EDIT_COPY:
  1461.                 get(lv_edit, MUIA_List_Active, &pos);
  1462.                 DoMethod(lv_edit, MUIM_List_GetEntry, pos, &line);
  1463.                 DoMethod(lv_edit, MUIM_List_Insert, &line, 1, pos);
  1464.                 set(lv_edit, MUIA_List_Active, pos);
  1465.             break;
  1466.  
  1467.             case ID_EDIT_REMOVE:
  1468.                 get(lv_edit, MUIA_List_Active, &pos);
  1469.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1470.  
  1471.                 check_edit_entries();
  1472.             break;
  1473.  
  1474.             case ID_EDIT_ACTIVATE:
  1475.                 set(lv_edit, MUIA_List_Quiet, TRUE);
  1476.                 get(lv_edit, MUIA_List_Active, &pos);
  1477.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1478.                 get(st_edit_string, MUIA_String_Contents, &line);
  1479.  
  1480.                 {
  1481.                     char *new_line, *insert_line;
  1482.  
  1483.                     new_line = strdup(line);
  1484.                     if (new_line)
  1485.                     {
  1486.                         *(new_line + strlen(new_line) - 1) = 0;
  1487.                         insert_line = new_line + 1;
  1488.                         DoMethod(lv_edit, MUIM_List_Insert, &insert_line, 1, pos);
  1489.                         free(new_line);
  1490.                     }
  1491.  
  1492.                 }
  1493.  
  1494.                 set(lv_edit, MUIA_List_Quiet, FALSE);
  1495.                 set(lv_edit, MUIA_List_Active, pos);
  1496.                 check_edit_entries();
  1497.             break;
  1498.  
  1499.             case ID_EDIT_DEACTIVATE:
  1500.                 set(lv_edit, MUIA_List_Quiet, TRUE);
  1501.                 get(lv_edit, MUIA_List_Active, &pos);
  1502.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1503.                 get(st_edit_string, MUIA_String_Contents, &line);
  1504.  
  1505.                 {
  1506.                     char *insert_line;
  1507.  
  1508.                     if (insert_line = AllocMem(MAXNAMELEN, MEMF_ANY))
  1509.                     {
  1510.                         sprintf(insert_line, "(%s)", line);
  1511.                         DoMethod(lv_edit, MUIM_List_Insert, &insert_line, 1, pos);
  1512.  
  1513.                         FreeMem(insert_line, MAXNAMELEN);
  1514.                     }
  1515.                 }
  1516.  
  1517.                 set(lv_edit, MUIA_List_Quiet, FALSE);
  1518.                 set(lv_edit, MUIA_List_Active, pos);
  1519.                 check_edit_entries();
  1520.             break;
  1521.  
  1522.  
  1523.             case ID_EDIT_ST_READY:
  1524.                 set(lv_edit, MUIA_List_Quiet, TRUE);
  1525.                 get(lv_edit, MUIA_List_Active, &pos);
  1526.                 DoMethod(lv_edit, MUIM_List_Remove, pos);
  1527.                 get(st_edit_string, MUIA_String_Contents, &line);
  1528.                 DoMethod(lv_edit, MUIM_List_Insert, &line, 1, pos);
  1529.                 set(lv_edit, MUIA_List_Quiet, FALSE);
  1530.                 set(lv_edit, MUIA_List_Active, pos);
  1531.             break;
  1532.  
  1533.  
  1534.             case ID_EDIT_SAVE:
  1535.                 save_tooltypes();
  1536.                 close_edit_window();
  1537.                 edit_window_open = FALSE;
  1538.             break;
  1539.  
  1540.             case ID_EDIT_CANCEL:
  1541.                 close_edit_window();
  1542.                 edit_window_open = FALSE;
  1543.             break;
  1544.  
  1545.  
  1546.             /*** default ***/
  1547.  
  1548.             default:
  1549.                 if (id)
  1550.                     printf("ID: %d = %08lx\n", id, id);
  1551.             break;
  1552.         }
  1553.  
  1554.         if (not_end && signal)
  1555.             Wait(signal);
  1556.     }
  1557.  
  1558.     fail(app, NULL);
  1559. }
  1560.  
  1561.  
  1562.